package com.fjec.market.controller;

import com.fjec.market.service.IStatService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/")
public class StatController {

    @Resource
    private IStatService service;

    /**
     * 统计果农
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/farmer/data")
    public List<Map<String, Object>> statFarmerData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statFarmerData(days);
        return resultMap;
    }

    /**
     * 统计分拣
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/sorting/data")
    public List<Map<String, Object>> statSortingPlantData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statBusinessData(days, 3);
        return resultMap;
    }

    /**
     * 统计农资
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/material/data")
    public List<Map<String, Object>> statMaterialData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statMaterialData(days);
        return resultMap;
    }

    /**
     * 统计包装
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/pkg/data")
    public List<Map<String, Object>> statPkgPlantData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statBusinessData(days, 5);
        return resultMap;
    }

    /**
     * 统计采购
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/purchase/data")
    public List<Map<String, Object>> statPurchaseData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statPurchaseData(days);
        return resultMap;
    }

    /**
     * 统计所有用户数量
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/all/personal/data")
    public List<Map<String, Object>> statAllPersonalData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statPersonalData(days, null);
        return resultMap;
    }

    /**
     * 统计普通用户数量
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/personal/data")
    public List<Map<String, Object>> statPersonalData(@RequestParam("days") Integer days) {
        List<Map<String, Object>> resultMap = service.statPersonalData(days, 1);
        return resultMap;
    }


    /**
     * 统计订单数量，金额
     *
     * @param days
     * @return
     */
    @GetMapping("/stat/sub/order/data")
    public List<Map<String, Object>> statSubOrderNumData(int days) {
        List<Map<String, Object>> resultMap = service.statSubOrderNumData(days);
        return resultMap;
    }

    /**
     * 获取所有市场编码和名称
     *
     * @return
     */
    @GetMapping("/stat/get/all/market")
    public List<Map<String, Object>> getAllMarket() {
        return service.getAllMarketCode();
    }
}
